﻿namespace Api.Controllers
{
    /// <summary>
    /// 安装地点
    /// </summary>
    public class InstallAddressController : EditingBaseController<InstallAddressModel, InstallAddressFilterModel, IInstallAddressLogic>
    {
        public InstallAddressController(ICurrentUser currentUser, IInstallAddressLogic logic)
            : base(currentUser, logic)
        {
        }

        #region 启用/禁用  Patch
        [HttpPatch]
        [Route("{id}")]
        public async Task<int> Del(int id)
        {
            return await Task.Run(() => _logic.UpdateIsDelete(true, id));
        }

        [HttpPatch]
        public async Task<int> BatchDel([FromBody] List<int> ids)
        {
            return await Task.Run(() => _logic.UpdateIsDelete(true, ids.ToArray()));
        }

        [HttpPatch]
        [Route("{id}")]
        public async Task<int> UnDel(int id)
        {
            return await Task.Run(() => _logic.UpdateIsDelete(false, id));
        }

        [HttpPatch]
        public async Task<int> BatchUnDel([FromBody] List<int> ids)
        {
            return await Task.Run(() => _logic.UpdateIsDelete(false, ids.ToArray()));
        }
        #endregion

        #region 默认过滤掉被禁用的搜索  GetSearchWithIsDelete  Post
        [HttpPost]
        public async Task<IEnumerable<InstallAddressModel>> GetSearchWithIsDelete([FromBody] InstallAddressFilterModel filterModel, string orderBy = null, int? top = null)
        {
            filterModel._IsDelete = false;
            return await Task.Run(() => _logic.GetSearch(filterModel, orderBy, top));
        }
        #endregion
        
    }
}
